#include<iostream>
#include<cstring>
using namespace std;
const int N = 2e4 + 10, M = 2e5 + 10;
int h[N], e[M], ne[M], w[M], idx;
int color[N];
int n, m;
void add(int a, int b, int c)
{
	e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}

bool dfs(int u, int d, int x)
{
	color[u] = d;
	for (int i = h[u]; ~i; i = ne[i]) {
		int j = e[i];
		if (w[i] <= x)continue;
		if (color[j]) {
			if (color[j] == d)return 0;
		}
		else if (!dfs(j, 3 - d, x))return 0;
		/*if (color[j]) {
			if (w[i] <= x)continue;
			return 
		}
		if (!color[j]) {
			if (!dfs(j, 3 - d, x))return 0;
		}*/
	}
	return 1;
}
bool check(int x)
{
	memset(color, 0, sizeof(color));
	for (int i = 1; i <= n; i++) {
		if (!color[i]) {
			if (!dfs(i, 1, x))return 0;
		}
	}
	return 1;
}
int main()
{
	cin >> n >> m;
	memset(h, -1, sizeof(h));
	while (m--) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		add(a, b, c);
		add(b, a, c);
	}
	int l = 0, r = 1e9 + 1;
	while (l + 1 < r) {
		int mid = l + r >> 1;
		if (check(mid))r = mid;
		else l = mid;
	}
	cout << r << endl;
	return 0;
}